@model WishlistModel
@using Nop.Core
@using Nop.Core.Domain.Tax
@inject IWebHelper webHelper
@inject IWorkContext workContext
@{
    Layout = "_ColumnsOne";

    //title
    NopHtml.AddTitleParts(T("PageTitle.Wishlist").Text);
    //page class
    NopHtml.AppendPageCssClassParts("html-wishlist-page");
}
<div class="page wishlist-page">
    <div class="page-title">
        <h1>
            @if (Model.IsEditable)
            {
                @T("Wishlist")
            }
            else
            {
                @string.Format(T("Wishlist.WishlistOf").Text, Model.CustomerFullname)
            }
        </h1>
    </div>
    <div class="page-body">
        @if (Model.Items.Count > 0)
        {
            <div class="wishlist-content">
                @if (Model.Warnings.Count > 0)
                {
                    <div class="message-error">
                        <ul>
                            @foreach (var warning in Model.Warnings)
                            {
                                <li>@warning</li>
                            }
                        </ul>
                    </div>
                }
                <form asp-route="Wishlist" method="post">
                    <div class="table-wrapper">
                        <table class="cart">
                            <colgroup>
                                @if (Model.DisplayAddToCart)
                                {
                                    <col width="1" />
                                }
                                @if (Model.ShowSku)
                                {
                                    <col width="1" />
                                }
                                @if (Model.ShowProductImages)
                                {
                                    <col width="1" />
                                }
                                <col />
                                <col width="1" />
                                <col width="1" />
                                <col width="1" />
                                @if (Model.IsEditable)
                                {
                                    <col width="1" />
                                }
                            </colgroup>
                            <thead>
                                <tr>
                                    @if (Model.DisplayAddToCart)
                                    {
                                        <th class="add-to-cart">
                                            @T("ShoppingCart.AddToCart")
                                        </th>
                                    }
                                    @if (Model.ShowSku)
                                    {
                                        <th class="sku">
                                            @T("ShoppingCart.SKU")
                                        </th>
                                    }
                                    @if (Model.ShowProductImages)
                                    {
                                        <th class="product-picture">
                                            @T("ShoppingCart.Image")
                                        </th>
                                    }
                                    <th class="product">
                                        @T("ShoppingCart.Product(s)")
                                    </th>
                                    <th class="unit-price">
                                        @T("ShoppingCart.UnitPrice")
                                    </th>
                                    <th class="quantity">
                                        @T("ShoppingCart.Quantity")
                                    </th>
                                    <th class="subtotal">
                                        @T("ShoppingCart.ItemTotal")
                                    </th>
                                    @if (Model.IsEditable)
                                    {
                                        <th class="remove-from-cart">
                                            @T("ShoppingCart.Remove")
                                        </th>
                                    }
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.Items)
                                {
                                    <tr>
                                        @if (Model.DisplayAddToCart)
                                        {
                                            <td class="add-to-cart">
                                                <label class="td-title">@T("ShoppingCart.AddToCart"):</label>
                                                <input type="checkbox" name="addtocart" value="@(item.Id)" />
                                            </td>
                                        }
                                        @if (Model.ShowSku)
                                        {
                                            <td class="sku">
                                                <label class="td-title">@T("ShoppingCart.SKU"):</label>
                                                <span class="sku-number">@item.Sku</span>
                                            </td>
                                        }
                                        @if (Model.ShowProductImages)
                                        {
                                            <td class="product-picture">
                                                <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })"><img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" /></a>
                                            </td>
                                        }
                                        <td class="product">
                                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" class="product-name">@item.ProductName</a>
                                            @if (!string.IsNullOrEmpty(item.AttributeInfo))
                                            {
                                                <div class="attributes">
                                                    @Html.Raw(item.AttributeInfo)
                                                </div>
                                            }
                                            @if (!string.IsNullOrEmpty(item.RecurringInfo))
                                            {
                                                <div class="recurring-info">
                                                    @Html.Raw(item.RecurringInfo)
                                                </div>
                                            }
                                            @if (!string.IsNullOrEmpty(item.RentalInfo))
                                            {
                                                <div class="rental-info">
                                                    @Html.Raw(item.RentalInfo)
                                                </div>
                                            }
                                            @if (Model.IsEditable && item.AllowItemEditing)
                                            {
                                                var editCartItemUrl = Url.RouteUrl("Product", new { SeName = item.ProductSeName }, webHelper.GetCurrentRequestProtocol());
                                                editCartItemUrl = webHelper.ModifyQueryString(editCartItemUrl, "updatecartitemid", item.Id.ToString());
                                                <div class="edit-item">
                                                    <a href="@editCartItemUrl">@T("Common.Edit")</a>
                                                </div>
                                            }
                                            @if (item.Warnings.Count > 0)
                                            {
                                                <div class="message-error">
                                                    <ul>
                                                        @foreach (var warning in item.Warnings)
                                                        {
                                                            <li>@Html.Raw(warning)</li>
                                                        }
                                                    </ul>
                                                </div>
                                            }
                                        </td>
                                        <td class="unit-price">
                                            <label class="td-title">@T("ShoppingCart.UnitPrice"):</label>
                                            <span class="product-unit-price">@item.UnitPrice</span>
                                        </td>
                                        <td class="quantity">
                                            <label class="td-title">@T("ShoppingCart.Quantity"):</label>
                                            @if (Model.IsEditable)
                                            {
                                                if (item.AllowedQuantities.Count > 0)
                                                {
                                                    <select name="itemquantity@(item.Id)" class="qty-dropdown">
                                                        @foreach (var qty in item.AllowedQuantities)
                                                        {
                                                            <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                        }
                                                    </select>
                                                }
                                                else
                                                {
                                                    <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input" aria-label="@T("ShoppingCart.Quantity")" />
                                                }
                                            }
                                            else
                                            {
                                                <span class="product-quantity">@item.Quantity</span>
                                            }
                                        </td>
                                        <td class="subtotal">
                                            <label class="td-title">@T("ShoppingCart.ItemTotal"):</label>
                                            <span class="product-subtotal">@item.SubTotal</span>
                                            @if (!string.IsNullOrEmpty(item.Discount))
                                            {
                                                <div class="discount">
                                                    @T("ShoppingCart.ItemYouSave", item.Discount)
                                                </div>
                                                if (item.MaximumDiscountedQty.HasValue)
                                                {
                                                    <div class="discount-additional-info">
                                                        @T("ShoppingCart.MaximumDiscountedQty", item.MaximumDiscountedQty.Value)
                                                    </div>
                                                }
                                            }
                                        </td>
                                        @if (Model.IsEditable)
                                        {
                                            <td class="remove-from-cart">
                                                <input type="checkbox" name="removefromcart" id="removefromcart@(item.Id)" value="@(item.Id)" aria-label="@T("ShoppingCart.Remove")" />
                                                <button type="button" name="updatecart" class="remove-btn" onclick="$('#removefromcart@(item.Id)').attr('checked', true); $('#updatecart').click();"></button>
                                            </td>
                                        }
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                    @if (Model.Items.Count > 0 && Model.DisplayTaxShippingInfo)
                    {
                        var inclTax = await workContext.GetTaxDisplayTypeAsync() == TaxDisplayType.IncludingTax;
                        //tax info is already included in the price (incl/excl tax). that's why we display only shipping info here
                        //of course, you can modify appropriate locales to include VAT info there
                        <div class="tax-shipping-info">
                            @T(inclTax ? "Wishlist.TaxShipping.InclTax" : "Wishlist.TaxShipping.ExclTax", Url.RouteUrl("Topic", new { SeName = await Html.GetTopicSeNameAsync("shippinginfo") }))
                        </div>
                    }
                    <div class="buttons">
                        @if (Model.IsEditable)
                        {
                            <button type="submit" name="updatecart" id="updatecart" class="button-2 update-wishlist-button">@T("Wishlist.UpdateCart")</button>
                        }
                        @if (Model.DisplayAddToCart)
                        {
                            <button type="submit" name="addtocartbutton" class="button-2 wishlist-add-to-cart-button">@T("ShoppingCart.AddToCart")</button>
                        }
                        @if (Model.IsEditable && Model.EmailWishlistEnabled)
                        {
                            <button type="button" class="button-2 email-a-friend-wishlist-button" onclick="setLocation('@Url.RouteUrl("EmailWishlist")')">@T("Wishlist.EmailAFriend")</button>
                        }
                    </div>
                </form>
            </div>
        }
        else
        {
            <div class="no-data">
                @T("Wishlist.CartIsEmpty")
            </div>
        }
        @if (Model.IsEditable && Model.Items.Count > 0)
        {
            var wishlistUrl = Url.RouteUrl("Wishlist", new { customerGuid = Model.CustomerGuid }, webHelper.GetCurrentRequestProtocol());
            <div class="share-info">
                <span class="share-label">@T("Wishlist.YourWishlistURL"):</span>
                <a href="@wishlistUrl" class="share-link">@wishlistUrl</a>
            </div>
        }
    </div>
</div>